package softswitch.ws;

import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import softswitch.model.CallLog;
import softswitch.model.Circuit;
import softswitch.model.Country;
import softswitch.model.Did;
import softswitch.model.Offer;
import softswitch.model.OfferDetail;
import softswitch.model.OfferGroup;
import softswitch.model.Operator;
import softswitch.model.Package;
import softswitch.model.Plan;
import softswitch.model.PlanDetail;
import softswitch.model.Restriction;
import softswitch.model.Route;
import softswitch.model.RouteGroup;
import softswitch.model.RoutePrefix;
import softswitch.service.CallDetailService;
import softswitch.service.CallLogDAO;
import softswitch.service.CallSummaryDispositionDAO;
import softswitch.service.CallSummaryOperatorDAO;
import softswitch.service.CallSummaryRouteGroupService;
import softswitch.service.CircuitDAO;
import softswitch.service.DidDAO;
import softswitch.service.OfferDAO;
import softswitch.service.OfferDetailDAO;
import softswitch.service.OfferGroupDAO;
import softswitch.service.OperatorDAO;
import softswitch.service.PackageDAO;
import softswitch.service.PackageSummaryService;
import softswitch.service.PlanDAO;
import softswitch.service.PlanDetailDAO;
import softswitch.service.RestrictionDAO;
import softswitch.service.RouteGroupDAO;
import softswitch.service.RoutePrefixDAO;


@Stateless
public class SoftswitchService {

    @EJB
    ReportService reportService;
    
    @EJB
    AgiProcessService callProcessorService;
    
    @EJB
    CdrProcessService cdrProcessService;

  

    @EJB
    CircuitDAO circuitDAO;

    @EJB
    CallDetailService calldetailDAO;
    
    @EJB
    CallLogDAO calllogDAO;

    @EJB
    RestrictionDAO restrictionDAO;

    @EJB
    CallSummaryRouteGroupService callsummaryRouteGroupDAO;
    
    @EJB
    CallSummaryOperatorDAO callsummaryOperatorDAO;
    
    @EJB
    CallSummaryDispositionDAO callsummaryDispositionDAO;
    

    @EJB
    DidDAO didDAO;

    @EJB
    PlanDAO planDAO;

    @EJB
    PlanDetailDAO planDetailDAO;

    @EJB
    PackageDAO packageDAO;

    @EJB
    PackageSummaryService packageSummaryDAO;

    @EJB
    RouteGroupDAO routegroupDAO;
    
    @EJB
    OperatorDAO operatorDAO;

    @EJB
    RoutePrefixDAO routeprefixDAO;

    @EJB
    OfferGroupDAO offerGroupDAO;

    @EJB
    OfferDAO offerDAO;

    @EJB
    OfferDetailDAO offerDetailDAO;


    public String getVersion() {
        return "1.0";
    }

    //-------------------------------------------------------------------------------
    public Circuit getCircuitById(Integer id) {
        return circuitDAO.getById(id);
    }

    public Circuit saveCircuit(Circuit circuit) {
        return circuitDAO.save(circuit);
    }

    public Circuit updateCircuit(Circuit circuit) {
        return circuitDAO.update(circuit);
    }

    public void deleteCircuit(Integer id) {
        circuitDAO.delete(id);
    }

    public Circuit getCircuitByCode(Long code) {
        return circuitDAO.getByCode(code);
    }

    public List<Circuit> listCircuits(Date activationStartdate, Date activationEnddate, Boolean enabled ) {
        return circuitDAO.list(activationStartdate, activationEnddate ,enabled);
    }
    
    public List<Circuit> listCircuits(int first, int max) {
        return circuitDAO.list(first, max);
    }

    public List<Circuit> listCircuitsByOrganizationId(Integer organizationId) {
        return circuitDAO.listByOrganizationId(organizationId);
    }

    public List<Circuit> listCircuitsByPlan(Plan plan) {
        return circuitDAO.listByPlan(plan);
    }

    public Long getCircuitTotal() {
        return circuitDAO.getTotal();
    }

 

	//-------------------------------------------------------------------------------
	public CallLog saveCallLog(CallLog calllog) {
        return calllogDAO.save(calllog);
    }
	public List<CallLog> getCallLogsByCircuitDestination(Circuit circuit,String destination, Date startdate) {
        return calllogDAO.listByCircuitDestination(circuit,destination,startdate);
    }
	//-------------------------------------------------------------------------------
    
    
    public Restriction getRestrictionById(Integer id) {
        return restrictionDAO.getById(id);
    }

    public Restriction saveRestriction(Restriction restriction) {
        return restrictionDAO.save(restriction);
    }

    public Restriction updateRestriction(Restriction restriction) {
        return restrictionDAO.update(restriction);
    }

    public void deleteRestriction(Integer id) {
        restrictionDAO.delete(id);
    }

    public List<Restriction> listRestrictions(int first, int max) {
        return restrictionDAO.list(first, max);
    }

    public List<Restriction> listRestrictionsByCircuit(Circuit circuit) {
        return restrictionDAO.listByCircuit(circuit);
    }


    public Did getDidById(Integer id) {
        return didDAO.getById(id);
    }

    public Did saveDid(Did did) {
        return didDAO.save(did);
    }

    public Did updateDid(Did did) {
        return didDAO.update(did);
    }

    public void deleteDid(Integer id) {
        didDAO.delete(id);
    }

    public List<Did> listDids(int first, int max) {
        return didDAO.list(first, max);
    }

    public Did getDidByNumber(Integer number) {
        return didDAO.getByNumber(number);
    }

    public List<Did> listByCircuit(Circuit circuit) {
        return didDAO.listByCircuit(circuit);
    }

    public Long getDidTotalItemsByCircuit(Circuit circuit) {
        return didDAO.listTotalItemsByCircuit(circuit);
    }

    public Double getDidTotalPriceByCircuit(Circuit circuit) {
        return didDAO.listTotalPriceByCircuit(circuit);
    }

	//-------------------------------------------------------------------------------
    public Plan getPlanById(Integer id) {
        return planDAO.getById(id);
    }

    public Plan savePlan(Plan plan) {
        return planDAO.save(plan);
    }

    public Plan updatePlan(Plan plan) {
        return planDAO.update(plan);
    }

    public void deletePlan(Integer id) {
        planDAO.delete(id);
    }

    public List<Plan> listPlans(int first, int max) {
        return planDAO.list(first, max);
    }

    public Plan getPlanByCode(Integer code) {
        return planDAO.getByCode(code);
    }

	//-------------------------------------------------------------------------------
    public PlanDetail getPlanDetailById(Integer id) {
        return planDetailDAO.getById(id);
    }

    public PlanDetail savePlanDetail(PlanDetail plandetail) {
        return planDetailDAO.save(plandetail);
    }

    public PlanDetail updatePlanDetail(PlanDetail plandetail) {
        return planDetailDAO.update(plandetail);
    }

    public void deletePlanDetail(Integer id) {
        planDetailDAO.delete(id);
    }

    public List<PlanDetail> listPlanDetails(int first, int max) {
        return planDetailDAO.list(first, max);
    }

    public List<PlanDetail> listPlanDetailsByPlan(Plan plan) {
        return planDetailDAO.listByPlan(plan);
    }

    public PlanDetail getPlanDetailByPlanRoute(Plan plan, Route route) {
        return planDetailDAO.getByPlanRoute(plan, route);
    }

	//-------------------------------------------------------------------------------
    public Package getPackageById(Integer id) {
        return packageDAO.getById(id);
    }

    public Package savePackage(Package packag) {
        return packageDAO.save(packag);
    }

    public Package updatePackage(Package packag) {
        return packageDAO.update(packag);
    }

    public void deletePackage(Integer id) {
        packageDAO.delete(id);
    }

    public List<Package> listPackages(int first, int max) {
        return packageDAO.list(first, max);
    }

    public List<Package> listPackagesByCircuit(Circuit circuit) {
        return packageDAO.listByCircuit(circuit);
    }

    public List<Package> listPackagesByOffer(Offer offer) {
        return packageDAO.listByOffer(offer);
    }

    public List<Package> listPackagesByCircuitOffer(Circuit circuit, Offer offer) {
        return packageDAO.listByCircuitOffer(circuit, offer);
    }

	

	//-------------------------------------------------------------------------------
    public RouteGroup getRouteGroupById(Integer id) {
        return routegroupDAO.getById(id);
    }

    public RouteGroup getRouteGroupByCode(Integer code) {
        return routegroupDAO.getByCode(code);
    }

    public RouteGroup getRouteGroupByName(String name) {
        return routegroupDAO.getByName(name.trim());
    }

    public RouteGroup saveRouteGroup(RouteGroup routegroup) {
        return routegroupDAO.save(routegroup);
    }

    public RouteGroup updateRouteGroup(RouteGroup routegroup) {
        return routegroupDAO.update(routegroup);
    }

    public void deleteRouteGroup(Integer id) {
        routegroupDAO.delete(id);
    }

    public List<RouteGroup> listRouteGroups(int first, int max) {
        return routegroupDAO.list(first, max);
    }

	//-------------------------------------------------------------------------------
    public RoutePrefix getRoutePrefixById(Integer id) {
        return routeprefixDAO.getById(id);
    }

    public RoutePrefix getRoutePrefixByPrefix(Integer prefix) {
        return routeprefixDAO.getByPrefix(prefix);
    }

    public RoutePrefix saveRoutePrefix(RoutePrefix routeprefix) {
        return routeprefixDAO.save(routeprefix);
    }

    public RoutePrefix updateRoutePrefix(RoutePrefix routeprefix) {
        return routeprefixDAO.update(routeprefix);
    }

    public void deleteRoutePrefix(Integer id) {
        routeprefixDAO.delete(id);
    }

    public List<RoutePrefix> listRoutePrefixes(int first, int max) {
        return routeprefixDAO.list(first, max);
    }

    public List<RoutePrefix> listRoutePrefixesByRoute(Route route) {
        return routeprefixDAO.listByRoute(route);
    }
    
    public RoutePrefix getRoutePrefixByDestination(String destination) {
        return routeprefixDAO.getByDestination(destination);
    }
  
	//-------------------------------------------------------------------------------
    public OfferGroup getOfferGroupById(Integer id) {
        return offerGroupDAO.getById(id);
    }

    public OfferGroup saveOfferGroup(OfferGroup offergroup) {
        return offerGroupDAO.save(offergroup);
    }

    public OfferGroup updateOfferGroup(OfferGroup offergroup) {
        return offerGroupDAO.update(offergroup);
    }

    public void deleteOfferGroup(Integer id) {
        offerGroupDAO.delete(id);
    }

    public List<OfferGroup> listOfferGroups(int first, int max) {
        return offerGroupDAO.list(first, max);
    }

	//-------------------------------------------------------------------------------
    public Offer getOfferById(Integer id) {
        return offerDAO.getById(id);
    }

    public Offer saveOffer(Offer offer) {
        return offerDAO.save(offer);
    }

    public Offer updateOffer(Offer offer) {
        return offerDAO.update(offer);
    }

    public void deleteOffer(Integer id) {
        offerDAO.delete(id);
    }

    public List<Offer> listOffers(int first, int max) {
        return offerDAO.list(first, max);
    }

    public List<Offer> listOffersByOfferGroup(OfferGroup offergroup) {
        return offerDAO.listByOfferGroup(offergroup);
    }

	//-------------------------------------------------------------------------------
    public OfferDetail getOfferDetailById(Integer id) {
        return offerDetailDAO.getById(id);
    }

    public OfferDetail saveOfferDetail(OfferDetail offerdetail) {
        return offerDetailDAO.save(offerdetail);
    }

    public OfferDetail updateOfferDetail(OfferDetail offerdetail) {
        return offerDetailDAO.update(offerdetail);
    }

    public void deleteOfferDetails(Integer id) {
        offerDetailDAO.delete(id);
    }

    public List<OfferDetail> listOfferDetails(int first, int max) {
        return offerDetailDAO.list(first, max);
    }

    public OfferDetail getOfferDetailByOfferRoute(Offer offer, Route route) {
        return offerDetailDAO.getByOfferRoute(offer, route);
    }

    public List<OfferDetail> listOfferDetailsByOffer(Offer offer) {
        return offerDetailDAO.listByOffer(offer);
    }

    public List<OfferDetail> listOfferDetailsByRoute(Route route) {
        return offerDetailDAO.listByRoute(route);
    }

    //-------------------------------------------------------------------------------
    public Operator getOperatorById(Integer id) {
        return operatorDAO.getById(id);
    }

    public Operator saveOperator(Operator operator) {
        return operatorDAO.save(operator);
    }

    public Operator updateOperator(Operator operator) {
        return operatorDAO.update(operator);
    }

    public void deleteOperator(Integer id) {
        operatorDAO.delete(id);
    }

    public List<Operator> listOperator(int first, int max) {
        return operatorDAO.list(first, max);
    }

    public Operator getOperatorByCode(Integer code) {
        return operatorDAO.getByCode(code);
    }

    public Operator getOperatorByNameCountry(String name, Country country) {
        return operatorDAO.getByNameCountry(name, country);
    }

	//-----------------------------------------------------------------------------------------------
    public void ReprocessCdrByMonth(Integer year, Integer month, Circuit circuit) {
    	cdrProcessService.reprocessByMonth(year, month, circuit);
        
    }


    
    
}
